package alarm

import (
	"github.com/gin-gonic/gin"
	"iot-base/auth/api/logic"
	"iot-base/auth/logger"
	types2 "iot-base/auth/types"
)

func ActiveAlarm(c *gin.Context) {
	uid := c.GetInt64("uid")
	requestId, _ := c.Get("RequestId")
	resp := types2.NewResult(c)
	var req types2.ReqActiveAlarm
	err := c.ShouldBind(&req)
	if err != nil {
		logger.Log.Errorf("ActiveAlarm [%s] err:=%v", requestId, err)
		resp.ErrorCode(types2.ParamsError, "")
		return
	}
	activeLogic := logic.NewAlarmLogic()
	result, err := activeLogic.ActiveAlarm(uid, req.StationID, req.Page, req.Size, req.StartTime, req.EndTime)
	if err != nil {
		logger.Log.Errorf("ActiveAlarm [%v] err:=%v", requestId, err)
		resp.ErrorCode(types2.ExceptionError, "")
		return
	}
	resp.Success(result)
}

func HistoryAlarm(c *gin.Context) {
	uid := c.GetInt64("uid")
	requestId, _ := c.Get("RequestId")
	resp := types2.NewResult(c)
	var req types2.ReqActiveAlarm
	err := c.ShouldBind(&req)
	if err != nil {
		logger.Log.Errorf("HistoryAlarm [%s] err:=%v", requestId, err)
		resp.ErrorCode(types2.ParamsError, "")
		return
	}
	alarmLogic := logic.NewAlarmLogic()
	result, err := alarmLogic.HistoryAlarm(uid, req.StationID, req.Page, req.Size, req.StartTime, req.EndTime)
	if err != nil {
		logger.Log.Errorf("HistoryAlarm [%v] err:=%v", requestId, err)
		resp.ErrorCode(types2.ExceptionError, "")
		return
	}
	resp.Success(result)
}
